<div id="cartDetail" align="center">
  <%= form_tag client_confirm_path, method: "post" do %>
  <table>

    <tr><td id="deliveryInfo">
      <div>
        <span class="groupTitle">1. <%= t("client.delivery_info") %></span>
        <hr/>
      </div>
      <% if @user %>
        <div>
          <input id="useProfileCheck" type='checkbox'/>
          <span class="use_profile"><%= t("client.use_profile") %></span>
        </div>
      <% end %>
      <table>
        <tr>
          <td class="label" align="right"><%= t("client.name") %>(*)</td>
          <td>
            <%= text_field_tag(
                  :name,
                  nil,
                  type: :text,
                  required: :required,
                  class: :text) %></td>
        </tr>
        <tr>
          <td class="label" align="right"><%= t("client.email") %></td>
          <td>
            <%= text_field_tag(
                  :email,
                  nil,
                  type: :email,
                  class: :text) %></td>
        </tr>
        <tr>
          <td class="label" align="right"><%= t("client.address") %>(*)</td>
          <td>
            <%= render(
                  partial: 'address',
                  locals: {
                    address: nil,
                    shipCostCallback: 'shipCostCallback' }) %>
          </td>
        </tr>
        <tr>
          <td class="label" align="right"><%= t("client.phone") %>(*)</td>
          <td>
            <%= text_field_tag(
                  :phone,
                  nil,
                  type: :tel,
                  required: :required,
                  class: :text) %></td>
        </tr>
      </table>
      <div>
        <span class="read_email_for_delivery_info">
          <%= t("client.read_email_for_delivery_info") %>
        </span>
      </div>
    </td></tr>
      
    <tr><td>
      <div id="deliveryMethod">
        <div>
          <span class="groupTitle">2. <%= t("client.delivery_method") %></span>
          <hr/>
        </div>
        <div class="content">
          <%= Settei.first.delivery_method.html_safe %>
        </div>
      </div>
    </td></tr>

    <tr><td>
      <div id="orderItems">
        <div>
          <span class="groupTitle">3. <%= t("client.order_items") %></span>
          <hr/>
        </div>
        <%= render partial: "order_item_list", locals: {order: @cart} %>
        <br/>
        <%= radio_button_tag(
              :payment,
              Order::PAYMENT_AT_DELIVERIED,
              Order::PAYMENT_AT_DELIVERIED == @cart.payment,
              onclick: "updateSubmitButton('#{t 'client.confirm'}');") %>
        <%= Order.get_payment_as_text Order::PAYMENT_AT_DELIVERIED %>
        <%= link_to '[?]', "#{client_info_path}#pay_at_delivery", target: '_blank' %>
        <br/>
        <%= radio_button_tag(
              :payment,
              Order::PAYMENT_BANK_TRANSFER,
              Order::PAYMENT_BANK_TRANSFER == @cart.payment,
              onclick: "updateSubmitButton('#{t 'client.confirm'}');") %>
        <%= Order.get_payment_as_text Order::PAYMENT_BANK_TRANSFER %>
        <%= link_to '[?]', "#{client_info_path}#pay_bank_transfer", target: '_blank' %>
        <br/>
        <%= radio_button_tag(
              :payment,
              Order::PAYMENT_VTC_PAY,
              Order::PAYMENT_VTC_PAY == @cart.payment,
              onclick: "updateSubmitButton('#{t 'client.pay'}');") %>
        <%= Order.get_payment_as_text Order::PAYMENT_VTC_PAY %>
        <%= link_to '[?]', "#{client_info_path}#pay_vtc", target: '_blank' %>

        <script type="text/javascript">
          function updateSubmitButton(val) {
            $("form input[type=submit]").val(val);
          }
        </script>
      </div>
    </td></tr>

    <tr><td>
      <% if @cart.sum_quantity > 0 %>
        <div style="margin-top:30px;" align="left">
          <%= submit_tag t("client.confirm"), class: "blueButton"  %>
          <button id="deleteOrderButton" class="redButton"
            style="margin-left:20px;"><%= t("client.delete_cart") %>
          </button>
        </div>
      <% end %>
    </td></tr>

  </table>
  <% end %>
</div>

<script type="text/javascript">
  <% if @user %>
    cart(
      "<%= client_delete_cart_path %>",
      "<%= client_remove_from_cart_remote_remote_path %>",
      "<%= @user.name %>",
      "<%= @user.email %>",
      <%= @user.address.to_json.html_safe %>,
      "<%= @user.phone %>"
    );
  <% else %>
    cart(
      "<%= client_delete_cart_path %>",
      "<%= client_remove_from_cart_remote_remote_path %>",
      null,
      null,
      null,
      null);
  <% end %>

  function shipCostCallback(shipCost) {
    changeOrderShipCost(shipCost);
    updateOrderSum();
  }
</script>